<?php 
/* OpenBIBLIO -- A library administration web interface
 * Copyright (C) 2002-2005 Fr&eacute;d&eacute;ric Descamps <lefred@tiscali.be>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 */

include_once("includes/db.inc");
include_once("includes/functions.inc");

session_start();
include_once("includes/session.inc");

ControleAcces("statclas.php",$login,$pwd,$user_id,session_id());

if(!$user_id)
{
 exit;
}

$title = _("Satistiques au niveau des classes");

include ("includes/header.inc");

$result = biblio_db_query("SELECT login FROM admin WHERE id = $user_id" ,$db);
$myrow = biblio_db_fetch_array($result);
$user = $myrow['login'] ;


echo "<CENTER><br>";

$sql = "SELECT id  FROM prets" ;	
$result = biblio_db_query($sql);
$total_emp=biblio_db_num_rows($result);

$sql = "SELECT id FROM classes" ;	

$result = biblio_db_query($sql);

$total_clas=biblio_db_num_rows($result);





echo _("Sur les <B>$total_clas</B> classes de l'&eacute;cole qui fr&eacute;quentent la biblioth&egrave;que voici leur r&eacute;partition :");



$requete = "select * from classes order by classe";

echo "<BR><BR><TABLE BORDER=1><tr><th>";
echo _("Classe");
echo "</th><th>";
echo _("Nbr d'emprunts");
echo "</th><th>";
echo _("R&eacute;partition");
echo "</th></tr>";

if(!($resultat = biblio_db_query($requete)))

{ print _("PROBLEME : ") .biblio_db_error(); }
else 
{
     while ($row = biblio_db_fetch_array($resultat)) 
     {      
           $classe_id = $row['id'];           
           $classe_nom =  $row['classe'];     
           $sql = "SELECT DISTINCT t1.livre_id, count(t1.livre_id) tot, t2.nom, t3.id FROM prets as t1 
           inner join eleves as t4 on t4.id = t1.eleve_id inner join classes as t3 on t3.id = t4.classe_id
           inner join livres as t2 on t2.id=t1.livre_id where t3.id = $classe_id group by livre_id order 
           by tot desc, nom LIMIT 5" ;	                                      
           put_log(8,"classe = $casse_nom",$user);
           $result = biblio_db_query($sql);
           $tot=0;
           while ($myrow = biblio_db_fetch_array($result)) 
           {
                $tot  = $tot + $myrow['tot'];                
           }    
           $i++;
           if ($i%2 == 1) {$col="WHITE";}
           else {$col="lightyellow";}                
           echo "<TR bgcolor=$col><TD>". $classe_nom ."</TD><TD align=right>". $tot ."</TD>";      
	   if ($total_emp == 0) $total_emp =1;
           $pct = sprintf("%2d",($tot / $total_emp) * 100);
           echo "<TD><IMG SRC=\"images/leftbar.gif\" height=\"15\" width=\"7\" Alt=\"$classe_nom : $pct%\" border=0>";
           echo"<IMG SRC=\"images/mainbar.gif\" height=\"15\" width=\"". $pct  ."\" Alt=\"$classe_nom : $pct%\" border=0>";
	   echo "<IMG SRC=\"images/rightbar.gif\" height=\"15\" width=\"7\" Alt=\"$classe_nom : $pct%\" border=0> $pct %</TD>"
;
     }
}
?>
</TABLE></CENTER>
<br><br>
<div>
<span id=left-text>
<A HREF="admin.php?menu=1">
<?php echo _("retour menu administration"); ?>
</A><BR>
<A HREF="index.php">
<?php echo _("retour menu principal"); ?>
</A></span>
</div>
<br>
<?php
include("includes/footer.inc");
?>
